SelectProductDialog.vue
<template>
  <div>
    <basic-dialog
      className="payable-table"
      :visible.sync="dialogVisible"
      :handleClose="handleCloseDialog"
      :title="title"
      :width="'60%'"
    >
      <div class="form-container">
        <el-form ref="queryData" :inline="true" :model="queryData" @submit.native.prevent>
          <el-form-item label="单据号:" prop="payableNo">
            <el-input
              v-model="queryData.payableNo"
              placeholder="请输入单据号"
              @keyup.enter.native="handleQueryData(1)"
            ></el-input>
          </el-form-item>
          <el-form-item label="商品代码:" prop="productCode">
            <el-input
              v-model="queryData.productCode"
              placeholder="请输入商品代码"
              @keyup.enter.native="handleQueryData(1)"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleQueryData(1)"
              >查询</el-button
            >
            <el-button @click="handleResetData('queryData')">清空</el-button>
          </el-form-item>
        </el-form>
      </div>
      <BasicTable
        ref="basicTable"
        :loading="tableInfo.loading"
        :columns="tableInfo.columns"
        :dataSource="tableInfo.list"
        :pagination="pagination"
        :pageSizes="pageSizes"
        :tableHeight="443"
        :showSelectCol="true"
        :check-selectable="checkSelectable"
        :selection-change="selectionChange"
        @pageChange="handlePageChange"
        @pageSizeChange="handlePageSizeChange"
      />
      <el-row type="flex" justify="center" slot="ft">
        <el-button
          type="primary"
          v-preventReClick
          :disabled="!tableInfo.selection.length"
          @click="handleSubmitSelections"
        >确定关联</el-button>
        <el-button @click="handleCloseDialog">取消</el-button>
      </el-row>
    </basic-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
import BasicDialog from '@/components/BasicDialog';
import BasicTable from '@/components/supplier/BasicTable';
import { getBtnsId } from '@/libs/btnsPermission';
import {
  queryTempRelationPayableListService, // 临采价格核查关联小票
} from '@api/supplier/supervision/tempPrice';
import { isResponseSuccess } from '@/pages/supplier/utils/bizUtils';

export default {
  name: 'SelectPayableDialog',
  components: {
    BasicDialog,
    BasicTable,
  },
  props: {
    title: {
      type: String,
      default: '关联单据'
    },
    dialogVisible: {
      type: Boolean,
      default: false
    },
    supplierId: {
      type: Number,
      default: 0
    },
  },
  data () {
    return {
      queryData: {
        payableNo: '', // 单据号
        productCode: '', // 商品代码
      },
      pageSizes: [10, 20, 30, 40],
      pagination: {
        current: 1,
        total: 0,
        size: 10
      },
      tableInfo: {
        list: [],
        loading: false,
        columns: [
          { title: '单据号', key: 'billNum', width: 90 },
          { title: '商品代码', key: 'productCode', width: 90 },
          { title: '商品名称', key: 'productName', width: 240 },
          { title: '规格', key: 'specification', },
          { title: '单位', key: 'unitName' },
        ],
        selection: []
      }
    };
  },
  computed: {
    ...mapGetters('permissions/systemBtns', ['showBtn'])
  },
  methods: {
    // 确定关联
    handleSubmitSelections () {
      this.$emit('handle-select', this.tableInfo.selection)
      this.handleCloseDialog();
    },
    // 勾选需要处理
    selectionChange (rows) {
      this.tableInfo.selection = rows;
    },
    // CheckBox 是否可以勾选
    checkSelectable ({ row, selections }) {
      const { billNum } = selections[0] || { billNum: '' }
      if (billNum) {
        return row.billNum === billNum
      } else {
        return true
      }
    },
    // 获取 表格数据
    handleQueryData (pageNum) {
      // const { supplierId } = this
      const { size } = this.pagination
      // if (!supplierId) {
      //   this.$message.error('请先选择供应商')
      //   this.handleCloseDialog()
      //   return
      // }
      this.tableInfo.loading = true;
      sessionStorage.setItem('buttonId', getBtnsId('查询'));
      // 临采价格核查关联小票
      // console.log('临采价格核查关联小票 :>> ', JSON.stringify(this.queryData))
      queryTempRelationPayableListService({ current: pageNum, size, ...this.queryData })
        .then(res => {
          this.tableInfo.loading = false;
          if (isResponseSuccess(res)) {
            const { records, total, current } = res.result;
            this.tableInfo.list = records;
            this.pagination.total = total;
            this.pagination.current = current;
            this.reloadTableLayout()
          }
        }).catch(() => {
          this.tableInfo.loading = false;
        });
    },
    // 分页状态变更
    handlePageChange (pageNum) {
      this.pagination.current = pageNum;
      this.handleQueryData(pageNum);
    },
    // 分页状态变更
    handlePageSizeChange (pageSize) {
      this.pagination.size = pageSize;
      this.handleQueryData(1);
    },
    // 重置查询条件
    handleResetData (formName) {
      this.$refs[formName].resetFields();
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$emit('update:dialogVisible', false);
      this.handleResetData('queryData')
      this.pagination = { current: 1, total: 0, size: 10 }
      this.tableInfo.list = []
      this.tableInfo.selection = []
    },
    // 表格DOM重新渲染
    reloadTableLayout () {
      this.$nextTick(() => {
        this.$refs.basicTable && this.$refs.basicTable.$refs.elTable.doLayout();
      });
    },
  }
};
</script>

<style lang="less">
.form-container {
  margin-bottom: 10px;
}
.payable-table {
  .el-table__fixed-header-wrapper,
  .el-table__header-wrapper {
    .el-checkbox__input {
      display: none !important;
    }
  }
}
</style>
